package aircraftWar;
import java.awt.image.BufferedImage;
import java.util.Random;

/**
 * 说明：小蜜蜂
 *
 * @author: PYS
 * @date: 2022/11/8
 **/
public class Bee extends FlyingObject implements EnemyAward {
    private int xSpeed;
    private int ySpeed;
    private int awardType;

    public Bee() {
        super(60, 51);
        Random rand = new Random();
        xSpeed = 1;
        ySpeed = 2;
        awardType = rand.nextInt(2);
    }

    public void step() {
        this.x += xSpeed; //x+(向右或向左)
        this.y += ySpeed; //y+(向下)
        if (this.x <= 0 || this.x >= 400-width) { //若x<=0或x>=(窗口宽-蜜蜂宽)，表示到两头了
            xSpeed *= -1; //则切换方法(正变负，负变正)
        }
    }

    int index = 1;
    public BufferedImage getImage() {
        if (isLive()) {
            return Images.bees[0];
        } else if (isDead()) {
            BufferedImage img = Images.bees[index++];
            if (index == Images.bees.length) {
                state = REMOVE;
            }
            return img;
        }
        return null;
    }

    public int getAwardType() {
        return this.awardType;
    }
}
